package com.ddz.service;

import com.ddz.model.User;
import com.ddz.model.enums.SystemEnums;
import com.ddz.util.JDBCUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserService {
    // 根据用户的账号获取用户对象
    public static User selectUser(String userID) {
        User user = null;
        String sql = "SELECT * FROM " + SystemEnums.SQL_TABLE_USER.getValue() + " WHERE userId =?";
        ResultSet resultSet = JDBCUtil.executeQuery(sql, userID);
        try {
            if(resultSet.next()){
                user = new User(resultSet.getString("userId"),resultSet.getString("password"),resultSet.getString("nickname"));
                user.setScore(resultSet.getInt("score"));
            }
        } catch (SQLException e) {
            System.out.println("SQL语句异常:"+e.getMessage());
            throw new RuntimeException(e);
        }
        return user;
    }
}
